package com.comm.db.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;

 

/**
 * ---------------
 * 
 * @author [Richie] 2008-7-15 : 下午01:37:17 -------------------------------- TODO
 *         要更改此生成的类型注释的模板，请转至 窗口 － 首选项 － Java － 代码样式 － 代码模板
 */
public class QueryImpl implements Query{
    
    private ResultSet rs = null;

    public  static Query  getInstance() {
            return new QueryImpl();
    }
    private QueryImpl(){
	rs=null;
	list=null;
    }
    int ColumnCount;

    private List<Map> list = new ArrayList<Map>();
    private  boolean isquerylist=false;
    public List list() {
	list = new ArrayList<Map>();
	isquerylist=true;
	 
	try {
	    
	 
	    ColumnCount = rs.getMetaData().getColumnCount();
	    //logger.info(" 列数 : " + ColumnCount);
	    Map<String, Object> map=null;
	    while (rs.next()) {
		map=new HashMap<String, Object>();
		for (int i = 1; i < (ColumnCount + 1); i++) {
		    map.put("item"+i, rs.getObject(i));
		   // System.out.println(rs.getObject(i));
		}
		list.add(map);

	    }
	} catch (SQLException e) {
	    e.printStackTrace();
	}
	return list;
    }

    public Iterator iterator() {
	if(!isquerylist) list();  
	return list.iterator();
    }

 
    public  void setRs(ResultSet rs) {
	this.rs = rs;
    }

}
